package com.college.heyuhua.controller;

import com.college.heyuhua.model.Thanks;
import com.college.heyuhua.service.IThanksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by 赵东坡 on 2019/2/5.
 * Time:23:32
 * 宇宙无敌赵牛逼，祈求永无bug
 */
@Controller
public class ThanksController {

    @Autowired
    private IThanksService thanksService;

    @RequestMapping("/thanks")
    public void thanks(@RequestParam("tusername") String tusername,
                       @RequestParam("thankscontext") String thankscontext,
                       HttpServletResponse response) {

        Thanks thanks = new Thanks();
        thanks.setThankscontext(thankscontext);
        thanks.setTusername(tusername);

        boolean flag = false;
        try{
            flag= thanksService.insertThanksInfo(thanks);
        }catch (Exception e)
        {
            System.out.println(e.getMessage());
        }

        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        writer.print(flag?"提交成功":"提交失败");
        writer.close();
        writer.flush();
    }


}
